package com.cskaoyan.service;

import com.cskaoyan.bean.MarketCouponUser;
import com.cskaoyan.bean.MarketCouponUserExample;
import com.cskaoyan.mapper.MarketCouponUserMapper;
import com.cskaoyan.util.MyBatisUtil;
import com.cskaoyan.util.TransactionUtil;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @author stone
 * @date 2023/03/18 02:08
 */
public class CouponUserServiceImpl implements CouponUserService {
    @Override
    public List<MarketCouponUser> findByOid(Integer orderId) {
        MarketCouponUserExample example = new MarketCouponUserExample();
        example.or().andOrderIdEqualTo(orderId).andDeletedEqualTo(false);
        MarketCouponUserMapper couponUserMapper = MyBatisUtil.getSqlSession().getMapper(MarketCouponUserMapper.class);
        return couponUserMapper.selectByExample(example);
    }

    @Override
    public int update(MarketCouponUser couponUser) {
        couponUser.setUpdateTime(new Date());
        MarketCouponUserMapper couponUserMapper = TransactionUtil.getMapper(MarketCouponUserMapper.class);
        return couponUserMapper.updateByPrimaryKeySelective(couponUser);
    }
}
